﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_sub_menu_list.ascx.vb"
    Inherits="Apps_Shares_Uc_sub_menu_list" %>
<%--==============================BEGIN Filter==============================--%>
<%--==============================END Filter==============================--%>
<table width="50%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#999999">
    <tr align="center" bgcolor="#99FFFF">
        <td colspan="2" bgcolor="#FFFFFF" class="th_data">
            ค้นหาข้อมูล
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            ชื่อระบบ :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID='ddlSystem' runat='server' AppendDataBoundItems="True" AutoPostBack="True"
                DataSourceID="ddlSystemSrc" DataTextField="main_system_name" DataValueField="main_system_code">
                <asp:ListItem Text='ระบบ' Value='0'></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="ddlSystemSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="SELECT [main_system_code], [main_system_name] FROM [stp_main_system] WHERE ([main_system_status] = @main_system_status) and  main_system_type > 0 ">
                <SelectParameters>
                    <asp:Parameter DefaultValue="1" Name="main_system_status" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            ชื่อเมนูระบบ :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID='ddlSystemMenu' runat='server' DataSourceID="ddlSystemMenuSrc"
                DataTextField="menu_system_name" DataValueField="menu_system_code">
            </asp:DropDownList>
            <asp:SqlDataSource ID="ddlSystemMenuSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="
                    SELECT 
                            [menu_system_code], 
                            [menu_system_name] 
                    FROM    [stp_menu_system] 
                    WHERE   (([main_system_code] = @main_system_code) 
                            AND ([menu_system_status] = @menu_system_status))">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddlSystem" DefaultValue="0" Name="main_system_code"
                        PropertyName="SelectedValue" Type="Int32" />
                    <asp:Parameter DefaultValue="1" Name="menu_system_status" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            ประเภทการทำงาน :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID='ddlCategory' runat='server' AppendDataBoundItems="True" DataSourceID="ddlCategorySrc"
                DataTextField="type_name" DataValueField="type_code">
                <asp:ListItem Text='ประเภทการทำงาน' Value='0'></asp:ListItem>
            </asp:DropDownList>
            <asp:SqlDataSource ID="ddlCategorySrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="SELECT [type_code], [type_name] FROM [master_type] WHERE ([type_status] = @type_status)">
                <SelectParameters>
                    <asp:Parameter DefaultValue="1" Name="type_status" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr align="left">
        <td width="47%" bordercolor="#CCCCCC" class="td_box">
            สถานะ :
        </td>
        <td width="53%" bordercolor="#CCCCCC" class="td_box">
            <asp:DropDownList ID='ddlStatus' runat="server">
                <asp:ListItem Text='สถานะ' Value='0'></asp:ListItem>
                <asp:ListItem Text='ใช้งาน' Value='1'></asp:ListItem>
                <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
    <tr align="center">
        <td colspan="2" bordercolor="#CCCCCC" class="td_data_end">
            <asp:Button ID='btnFilter' Text='<%$ Resources:Resource,BTN_SEARCH %>' runat='server' />
            <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
        </td>
    </tr>
</table>
<div style="margin:5px;display:block;width:100%">&nbsp;</div>
<%--==============================BEGIN Display==============================--%>
<br />
<asp:ListView ID="gvDisplay" runat="server" DataSourceID="gvDisplaySrc" DataKeyNames='sub_menu_code'
    EnableModelValidation="True">
    <LayoutTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#999999" border="0" align="center"
            width="100%">
            <tbody>
                <tr bgcolor="#ff9999" align="center">
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="Image1" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort0' runat='server' CommandName='Sort' CommandArgument='main_system_name'>
                                ชื่อระบบ
                        </asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="Image2" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort1' runat='server' CommandName='Sort' CommandArgument='menu_system_name'>
                                ชื่อเมนูระบบ
                        </asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        ลำดับ
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="sub_menu_name" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort2' runat='server' CommandName='Sort' CommandArgument='sub_menu_name'>
                                ชื่อเมนูระบบย่อย
                        </asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="type_code" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort3' runat='server' CommandName='Sort' CommandArgument='type_code'>
                                ประเภทการทำงาน
                        </asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="sub_menu_url" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort4' runat='server' CommandName='Sort' CommandArgument='sub_menu_url'>
                                URL
                        </asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data">
                        <asp:Image ID="sub_menu_status" runat="server" Visible="false" />
                        <asp:LinkButton ID='sort5' runat='server' CommandName='Sort' CommandArgument='sub_menu_status'>
                                สถานะ
                        </asp:LinkButton>
                    </td>
                    <td bgcolor="#ffffff" class="th_data col_delete">
                        <input id='icbHeader' type='checkbox' />
                        ลบข้อมูล
                    </td>
                </tr>
                <asp:PlaceHolder ID='itemPlaceholder' runat='server' />
                <tr bgcolor="#ff9999" align="center">
                    <td bgcolor="#ffffff" class="td_data_end" colspan="7">
                        <%-- ====================== Data Pager ======================--%>
                        <asp:DataPager ID="paging" runat="server" PagedControlID="gvDisplay" PageSize='10'>
                            <Fields>
                                <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="false"
                                    ShowNextPageButton='false' ShowPreviousPageButton='false' FirstPageText='<<' />
                                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowLastPageButton="false"
                                    ShowNextPageButton='false' ShowPreviousPageButton='true' PreviousPageText='<' />
                                <asp:NumericPagerField />
                                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowLastPageButton="false"
                                    ShowNextPageButton='true' ShowPreviousPageButton='false' NextPageText='>' />
                                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowLastPageButton="true"
                                    ShowNextPageButton='false' ShowPreviousPageButton='false' LastPageText='>>' />
                            </Fields>
                        </asp:DataPager>
                        <%-- ====================== Data Pager ======================--%>
                    </td>
                    <td bgcolor="#ffffff" class="td_data_end col_delete">
                        <asp:Button ID='btnDelete' runat='server' Text='ลบข้อมูล' OnClick='btnDelete_Click'
                            OnClientClick='<%$Resources:Resource,SCRIPT_CONFIRM_DELETE %>' />
                    </td>
                </tr>
            </tbody>
        </table>
    </LayoutTemplate>
    <EmptyDataTemplate>
        <br />
        <span class='star'>
            <center>
                ไม่พบข้อมูล</center>
        </span>
    </EmptyDataTemplate>
    <ItemTemplate>
        <tr>
            <td align="left" class="td_data" bordercolor="#CCCCCC"><%#Eval("main_system_name")%></td>
            <td align="left" class="td_data" bordercolor="#CCCCCC"><%#Eval("menu_system_name")%></td>
            <td align="center" class="td_data" bordercolor="#CCCCCC">
                <asp:HiddenField ID='hideSubMenuCode' runat='server' Value='<%#Eval("sub_menu_code") %>' />
                <%# Eval("SeqNo")%>
                <div class="hide">
                    <asp:RequiredFieldValidator ID="txtSubNameNameRequiredFieldValidator" runat="server"
                        ControlToValidate="txtSubNameName" ErrorMessage="กรุณากรอกชือเมนูย่อยระบบ" SetFocusOnError="True"
                        ValidationGroup="g1"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="ddlTypeRequiredFieldValidator" runat="server" ControlToValidate="ddlType"
                        ErrorMessage="กรุณาเลือกประเภทการทำงาน" InitialValue="0" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    <asp:ValidationSummary ID="fvValidationSummary" runat="server" ValidationGroup="g1"
                        ShowMessageBox='true' />
                </div>
            </td>
            <td align="left" class="td_data" bordercolor="#CCCCCC">
                <asp:TextBox ID='txtSubNameName' runat='server' Text='<%#Eval("sub_menu_name")%>'></asp:TextBox>
            </td>
            <td align="left" class="td_data" bordercolor="#CCCCCC">
                <asp:DropDownList ID='ddlType' runat='server' SelectedValue='<%# Eval("type_code") %>'
                    DataSourceID="ddlTypeSrc" DataTextField="type_name" DataValueField="type_code">
                </asp:DropDownList>
                <asp:SqlDataSource ID="ddlTypeSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                    SelectCommand="SELECT [type_code], [type_name] FROM [master_type] WHERE ([type_status] = @type_status)">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="1" Name="type_status" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
            <td align="left" class="td_data" bordercolor="#CCCCCC">
                <asp:TextBox ID='txtURL' runat='server' Text='<%#Eval("sub_menu_url")%>'></asp:TextBox>
            </td>
            <td align="center" class="td_data f_status" bordercolor="#CCCCCC">
                <asp:DropDownList ID='ddlStatus' runat='server' SelectedValue='<%# Eval("sub_menu_status") %>'
                    RepeatDirection="Horizontal" RepeatLayout="Flow">
                    <asp:ListItem Text='ใช้งาน' Value='1'></asp:ListItem>
                    <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                </asp:DropDownList>
            </td>
            <td align="center" class="td_data col_delete" bordercolor="#CCCCCC">
                <asp:CheckBox ID='icbItem' runat='server' />
            </td>
        </tr>
    </ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="gvDisplaySrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
    SelectCommand="exec [dbo].[USP_Filter_stp_sub_menu]
		@main_system_code,
		@menu_system_code ,
		@type_code ,
		@sub_menu_status ;" 
	UpdateCommand="UPDATE [stp_sub_menu]
        SET     [menu_system_code] = @menu_system_code,
                [sub_menu_name] = @sub_menu_name,
                [sub_menu_url] = @sub_menu_url,
                [type_code] = @type_code,
                [sub_menu_status] = @sub_menu_status,
                [staff_code_update] = @staff_code_update,
                [update_datetime] = getdate()
        WHERE   sub_menu_code = @sub_menu_code" 
    CancelSelectOnNullParameter="False" 
    DeleteCommand="EXEC  [dbo].[USP_GenericDelete] @tbl,@pid,@cid">
    <SelectParameters>
        <asp:Parameter Name="main_system_code" />
        <asp:Parameter Name="menu_system_code" />
        <asp:Parameter Name="type_code" />
        <asp:Parameter Name="sub_menu_status" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="menu_system_code" />
        <asp:Parameter Name="sub_menu_name" />
        <asp:Parameter Name="sub_menu_url" />
        <asp:Parameter Name="type_code" />
        <asp:Parameter Name="sub_menu_status" />
        <asp:SessionParameter DefaultValue="staff_code" Name="staff_code_update" SessionField='staff_code' />
        <asp:Parameter DefaultValue="staff_code" Name="staff_code_update" />
    </UpdateParameters>
    <DeleteParameters>
        <asp:Parameter DefaultValue="stp_sub_menu" Name="tbl" Type="String" />
        <asp:Parameter DefaultValue="sub_menu_code" Name="pid" Type="String" />
        <asp:Parameter DefaultValue="-1" Name="cid" Type="String" />
    </DeleteParameters>
</asp:SqlDataSource>
<center>
    <asp:Button ID="btnAdd" runat="server" Text="เพิ่มข้อมูล" PostBackUrl="~/Apps/sub_menu_fv.aspx?Insert=1" />
    <asp:Button ID="btnUpdate" runat="server" Text="บันทึกข้อมูล" ValidationGroup='g1' />
    <asp:Button ID="btnDelete" runat="server" Text="ลบข้อมูล" OnClick='btnDelete_Click' />
    <input type="reset" value='ยกเลิก' />
</center>
<%-- ====================== Data Pager ======================--%>
<%--==============================To mark all check box==============================--%>
<script type="text/javascript">
    matchTableCheckBox('icbHeader', 'icbItem');
    hideDeleteColumn();
    hilightInactive();
</script>